<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE>
<html>
  <head>    
    <title>添加二级分类</title>   
    <base href="<%=basePath%>">
	<link rel="stylesheet" type="text/css" href="/css/edittable.css"  ></link>  
	<link rel="stylesheet" type="text/css" href="/css/validate.css"  ></link>  
	<script type="text/javascript"  src="/js/jquery-1.8.0.js"></script>
	<script>
		var result = false;
		$(function(){
			$("#cateName").blur(function(){
				if($("#bigcateId").val()==-1){
					$("#bigcateId_msg").html("请选择父级分类");
					$("#bigcateId_msg").css("color","red");
					result = false;
				}else{
					$("#bigcateId_msg").html("√");
					$("#bigcateId_msg").css("color","green");
					var a = $("#bigcateId").val();
					var b = $("#cateName").val();
					var text = /^.{2,20}$/;
					if(text.test(b)){
						$.ajax({
							url:"GoodsServlet.do",
							type:"post",
							data:{parentId:a,cateName:b,flag:"checkSonName"},
							success:function(data){
								if(data==1){
									$("#cateName_msg").html("√");
									$("#cateName_msg").css("color","green");
									result=true;
								}else{
									$("#cateName_msg").html("分类名称已存在");
									$("#cateName_msg").css("color","red");
									result=false;
								}
							}
						})
					}else{
						$("#cateName_msg").html("输入错误，长度 2-20 位非空白字符");
						$("#cateName_msg").css("color","red");
						result1=false;
					}
				}
			})
		})
		
		function validateInput(){
			if(result){
				var l = confirm("确认添加吗");
				if(l){
					return true;
				}else{
					return false;
				}
			}else{
				alert("请按要求填写");
				return false;
			}
		}
	</script>
  </head>
  
  <body>
     <div class ="div_title">
		 <div class="div_titlename"><span>商品管理    添加二级分类</span></div>
	 </div>
				 
	 <form action="GoodsServlet.do?flag=addson" method="post"  onsubmit="return validateInput()">
	 	<input type="hidden" name="flag" value="addsmallcate" />
		 <table class="edit_table" >
		 		<tr>
		 			 	<td class="td_info">父级分类:</td>	
		 			 	<td class="td_input_short"> 
		 			 			<select  class="txtbox" name="bigcateId" id="bigcateId">
			 			 			<option value="-1">---请选择所属一级分类---</option>
			 			 			<c:forEach var="cate" items="${cateList}">
			 			 				<option value="${cate.id}">${cate.cateName}</option>
			 			 			</c:forEach>
		 			 			</select>
		 			 	</td>   
		 			 	<td>
		 			 		<label class="validate_info" id="bigcateId_msg"></label>
		 			 	</td> 
		 		</tr>
		 		
		 		<tr>
		 			 	<td class="td_info">分类名称:</td>	
		 			 	<td  class="td_input_short"> 
		 			 		<input type="text" class="txtbox" id="cateName" name="cateName" value="${param.cateName}"/> 
		 			 	</td>   
		 			 	<td>
		 			 		<label class="validate_info" id="cateName_msg">长度 2-20 位非空白字符</label>
		 			 	</td> 
		 		</tr>
		 		
		 		


		 		<tr>
		 			<td class="td_info">分类描述:</td>	
		 			<td  class="td_input_short"><textarea rows="4" cols="27" name="des" class="txtarea">${param.des}</textarea> </td>	
		 			<td><label></label></td>	
		 		</tr>
		 		<tr>
		 			<td class="td_info"> </td>	
		 			<td  class="td_input_short" > 
		 			<input class="form_btn" type="submit" value="提交" /> 
		 			<input type="reset"  class="form_btn"  value="重置" /> </td>	
		 			<td>
		 				<label id="result_msg" class="result_msg">${msg}</label>
		 			</td>	
		 		</tr>
		</table>
     </form>
     
     <script>
     	$(function(){
     		var c = "${param.bigcateId}";
     		$("option").each(function(){
     			if(this.value==c){
     				this.selected=true;
     			}
     		})
     			
     	})
     </script>
  </body>
</html>
